package Work02;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import cy.student;

import java.io.File;
import java.util.List;

public class demo {
    public static void main(String[] args) {
        File file = new File("D:\\cy-javaEE-project\\day01-xml-json\\src\\Work02\\a.json");
        String jsonString = FileUtil.readUtf8String(file);
//        System.out.println(jsonString);
        Order order = JSONUtil.toBean(jsonString, Order.class);
        System.out.println("Order ID:"+order.getOrderId());
        System.out.println("User ID:"+order.getUserId());
        System.out.println("Total Amount:"+order.getTotalAmount());

        for (OrderItem orderItem : order.getItems()) {
            System.out.println("Item ID:"+orderItem.getItemId()+","+"Quantity:"+orderItem.getQuantity()+","+"Price:"+orderItem.getPrice());
        }
        String jsonStr = JSONUtil.toJsonStr(order);
        System.out.println("JSON Output: " + jsonStr);

    }
}
